from user.models import User
from pms.common.utils import flatten_view


def update_user_by_view(uid, view, self=False):
    """ 根据前端视图更新人员对象 """
    user = User.objects.filter(id=uid)
    if self:
        rule = {
            'name': 'name'
        }
    else:
        rule = {
            'name': 'name',
            'rid': ['role', 'id']
        }
    argv = flatten_view(view, rule)
    user.update(**argv)
    return User.objects.get(id=uid)
